<!--  -->
<template>
  <div class="">
    <a-card>
      <div class="search-form-wrapper" ref="search">
        <a-form layout="inline">
          <a-row :gutter="48">
            <a-col :md="6" :sm="24">
              <a-form-item>
                <a-select v-model="queryParam.businessType" allow-clear placeholder="日志类型">
                  <a-select-option
                    v-for="(item, index) in logTypeList"
                    :key="index"
                    :value="item"
                    >{{ item }}</a-select-option
                  >
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="12" :sm="24">
              <a-form-item>
                <DateTimeRange
                  v-model="queryParam._dateRange"
                  :startDate.sync="queryParam.beginTime"
                  :endDate.sync="queryParam.endTime"
                  :placeholder="['创建开始时间', '创建结束时间']"
                />
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="24">
              <span class="table-page-search-submitButtons">
                <a-button type="primary" @click="handle">查询</a-button>
                <a-button style="margin-left: 8px" @click="() => (queryParam = {})">重置</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <a-table
        :loading="tableLoading"
        :columns="columns"
        :pagination="pagination"
        @change="(e) => handle(e)"
        :data-source="tableData"
        :scroll="{ y: tableHeight }"
      >
        <span slot="operName" slot-scope="text">
          {{ text }}
        </span>
      </a-table>
    </a-card>
  </div>
</template>

<script>
import { getLogList, getLogTypeList } from '@/api/set'
import { DateTimeRange } from '@/components'
const columns = [
  {
    title: '操作时间',
    dataIndex: 'operTime'
  },
  {
    title: '日志类型',
    dataIndex: 'businessType'
  },
  {
    title: '日志内容',
    dataIndex: 'content'
  },
  {
    title: '操作人',
    dataIndex: 'operName',
    scopedSlots: { customRender: 'operName' }
  }
]
export default {
  data() {
    return {
      visible: false,
      pagination: {
        current: 1,
        'show-size-changer': true,
        total: 0
      },
      tableData: [],
      tableLoading: false,
      advanced: false,
      queryParam: {
        pageNum: 1,
        pageSize: 10,
        _dateRange: [],
        beginTime:'',
        endTime:''
      },
      tabbarHeight: 420,
      queryParamKey: 'spu_name',
      columns,
      dateFormat: 'YYYY/MM/DD',
      dateList: [],
      logTypeList: []
    }
  },
  computed: {
    hasSelected() {
      return this.selectedRowKeys.length > 0
    },
    tableHeight() {
      return document.body.clientHeight - 220
    }
  },
  activated() {
    this.handle()
    this.getLogTypeList()
  },
  mounted() {
    this.handle()
    this.getLogTypeList()
  },
  components: { DateTimeRange },
  methods: {
    loadData() {
      this.tableLoading = true
      getLogList({ ...this.queryParam })
        .then((res) => {
          this.tableLoading = false
          console.log(res)
          this.tableData = res.rows
          this.pagination.total = res.total
        })
        .catch(() => {})
    },
    handle(v) {
      console.log('daozhegel')
      if (v && v.current) {
        if (this.queryParam.pageSize == v.pageSize) {
          this.pagination.current = v.current
          this.queryParam.pageNum = v.current
        } else {
          this.queryParam.pageSize = v.pageSize
          this.queryParam.pageNum = 1
          this.pagination.current = 1
        }
      } else {
        this.queryParam.pageNum = 1
        this.queryParam.pageSize = 10
        this.pagination.current = 1
      }

      this.loadData()
    },
    toggleAdvanced() {
      this.advanced = !this.advanced
    },
    dateChange(info) {
      console.log(this.dateList)
      if (info.length == 0) {
        this.queryParam.beginTime = ''
        this.queryParam.endTime = ''
      } else {
        this.queryParam.beginTime = info[0].format('yyyy-MM-DD') + ' 00:00:00'
        this.queryParam.endTime = info[1].format('yyyy-MM-DD') + ' 23:59:59'
      }
    },
    getLogTypeList() {
      getLogTypeList().then((res) => {
        console.log(res)
        this.logTypeList = res.data
      })
    }
  }
}
</script>

<style lang="less" scoped>
.empty {
  width: calc(100% + 50px);
  margin-left: -25px;
  height: 12px;
  background: #f7f8fa;
}
.search-box {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  min-height: 47px;
  margin-bottom: 19px;
  .type-list {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    .type-item {
      height: 45px;
      line-height: 45px;
      border-bottom: 2px solid #fff;
      padding: 0 20px;
      font-size: 14px;
      cursor: pointer;
    }
    .type-item.active {
      border-bottom: 2px solid #4393f2;
      font-size: 16px;
      font-weight: 500;
      color: #4393f2;
    }
  }
}
.search-form-wrapper {
  background: #f3f4f7;
  padding: 10px 20px 20px !important;
  margin-bottom: 20px;
  padding-bottom: 20px;
  /deep/ .ant-col {
    height: 45px;
  }
  /deep/ .ant-form-item {
    margin: 12px 0;
  }
  /deep/ .ant-btn {
    width: 68px;
    height: 32px;
    margin-top: 12px;
  }
}
</style>
